package com.rt.easyjava.base.modules.timerjob.service.job;


import com.rt.easyjava.base.modules.timerjob.dto.TmptTimerBizDto;
import com.rt.easyjava.base.modules.timerjob.service.job.jobStrategy.JobStrategy;
import com.rt.easyjava.base.modules.timerjob.service.job.jobStrategy.JobStrategyFactory;
import com.rt.easyjava.common.utils.others.DateTool;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.scheduling.quartz.QuartzJobBean;

@PersistJobDataAfterExecution//持久化
@DisallowConcurrentExecution//禁止并发执行(Quartz不要并发地执行同一个job定义（这里指一个job类的多个实例）)
@Slf4j
public class SpringJobBean extends QuartzJobBean {


	@Override
	protected void executeInternal(JobExecutionContext context) {
		TmptTimerBizDto tmptTimerBizDto = (TmptTimerBizDto)context.getMergedJobDataMap().get("tmptTimerBizDto");

		// 执行Job策略
		JobStrategy jobStrategy = JobStrategyFactory.getJobStrategy(tmptTimerBizDto);
		jobStrategy.execute();

		String taskName = context.getJobDetail().getJobDataMap().getString("name");
		log.info("---> Quartz job1， {},  {}, {} <----", DateTool.getCurrentDateStr1("yyyy-MM-dd HH:mm:ss.SSS"), context.getTrigger().getKey(), taskName);
	}


}
